<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body id='content'>
	<div style='height:100%;padding:0px' id='main' class='l1'>

		<h3 style='text-align:center' id='info_title'>超级管理<span id='voteType'>申请</span>投票</h3>


		<!--申请人员列表-->
		<div id='userList' style='text-align:center;line-height:50px'>
			<div style='display:flex'>
				<div style='flex:1;display:flex'>
					<div style='width:50px;height:50px;border:0px solid'>
						<img src="../img/s9.jpg" style='width:100%;height:100%;border-radius:25px' alt="">
					</div>
					<div style='flex:1;text-align:left;text-indent:15px'>征服</div>
				</div>
				<div style='flex:1'>11票</div>
				<div style='flex:1'>
					<span style='border:1px solid #777;background:#eee;padding:1px 5px;cursor:pointer'>投票</span>
				</div>
			</div>
		</div>



		<div style='color:red;font-size:12px;margin:30px'>
			注：当投票总数超过小区人数50%时，得票最高者当选为超级管理员！
		</div>
		<div style='text-align:center;margin:20px'><a href="area_detail.html" style='text-decoration:none'><button>返回</button></a></div>
	</div>



</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
if(!sessionStorage.current_area_id){
	history.go(-1);
}
var tokenSet = GetCityInfo();
var user_info = GetUserInfo();
/*
	### 获取超管任免申请信息
	注：此处后续需修改成从缓存获取是否有申请超管状态，并判断。
*/
function _getSuperAdminRegisterList(){
	var data = {
		type:'getSuperAdminRegisterList',
		area_id:sessionStorage.current_area_id
	}
	AjaxBefore(data,function(res){
		C(res);
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		if(tmp.type == 'apply'){
			$('#voteType').text('竟选');
		}else{
			$('#voteType').text('罢免');
		}
		if(tmp.data){
			ParseData(tmp.data);
		}
	});
}

function ParseData(data){
	if(typeof(data) != 'object' || data.length < 1){
		return;
	}
	var str = '';
	for(var i=0;i<data.length;i++){
		str += "<div style='margin:10px 0px;display:flex'><div style='flex:1;display:flex'><div style='width:50px;height:50px;border:0px solid'><img src='../img/s9.jpg' style='width:100%;height:100%;border-radius:25px' /></div><div style='flex:1;text-align:left;text-indent:15px'>"+data[i].admin_openid+"</div></div><div style='flex:1'>" +data[i].count+ " 票</div><div style='flex:1'><span onclick=addTicket('"+data[i].admin_openid+"') style='border:1px solid #777;background:#eee;padding:1px 5px;cursor:pointer'>投票</span></div></div>";
	}
	$('#userList').html(str);
}

//给申请超管的用户投票
function addTicket(admin_openid){

	if(!admin_openid){
		return;
	}
	if(admin_openid == user_info.openid){
		A('不能给自己投票！');
		return;
	}

	var data = {
		type:'addTicket',
		admin_openid:admin_openid,
		area_id:sessionStorage.current_area_id
	}
	AjaxBefore(data,function(res){
		C(res);
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		switch(tmp.stat){
			case 'err1':case 'err3':
				A('请求异常！');
				break;
			case 'err2':
				A('您已投过票了！');
				break;
			case 'ok':
				A('投票成功！');
				location.reload();
				break;
			case 'ok2':
				history.go(-1);
				break;
		}
		C(res);
	});
}

$(function(){
	_getSuperAdminRegisterList();
});
</script>